<template>
  <div v-loading="loading">
    <el-form ref="form" :model="form" :rules="rules" label-width="120px" class="dataForm">
      <el-row>
        <el-col :span="12">
          <el-form-item :label="$t('年份')" prop="year">
            <DatePicker v-model="form.year" type="year" value-format="yyyy" :placeholder="$t('年份')" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item :label="$t('季度')" prop="quarter">
            <el-select v-model="form.quarter" filterable :placeholder="$t('季度')">
              <el-option
                v-for="dict in quarterOptions"
                :key="dict.dictValue"
                :label="$t(dict.dictLabel)"
                :value="dict.dictValue"
              />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item :label="$t('基金总资产') + $t('金额单位')" prop="fundTotalAssets">
            <Money v-model="form.fundTotalAssets" unit="w" :placeholder="$t('基金总资产')" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item :label="$t('基金净资产') + $t('金额单位')" prop="fundNetAssets">
            <Money v-model="form.fundNetAssets" unit="w" :placeholder="$t('基金净资产')" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item :label="$t('账目净利润') + $t('金额单位')" prop="accountNetProfit">
            <Money v-model="form.accountNetProfit" unit="w" :placeholder="$t('账目净利润')" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item :label="$t('管理费用') + $t('金额单位')" prop="administrationCost">
            <Money v-model="form.administrationCost" unit="w" :placeholder="$t('管理费用')" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item :label="$t('审计费用') + $t('金额单位')" prop="auditCost">
            <Money v-model="form.auditCost" unit="w" :placeholder="$t('审计费用')" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item :label="$t('托管费') + $t('金额单位')" prop="custodyFee">
            <Money v-model="form.custodyFee" unit="w" :placeholder="$t('托管费')" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item :label="$t('管理费') + $t('金额单位')" prop="managementFee">
            <Money v-model="form.managementFee" unit="w" :placeholder="$t('管理费')" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item :label="$t('累计计提管理费总额') + $t('金额单位')" prop="manageTotalAmount">
            <Money v-model="form.manageTotalAmount" unit="w" :placeholder="$t('累计计提管理费总额')" />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item :label="$t('备注')" prop="remark">
            <el-input v-model="form.remark" type="textarea" maxlength="2000" show-word-limit :placeholder="$t('备注')" />
          </el-form-item>
        </el-col>
      </el-row>
      <FileTable :list.sync="form.fileList" data-type="bf_financial" :business-id="getDealId" :btn-show="!otherBtnHide" />
    </el-form>
    <div slot="footer" class="dialog-footer" style="text-align: right;">
      <!--保存 取消按钮-->
      <save-btn has-permi="bf:financial" />
    </div>
  </div>
</template>

<script>
    import { saveBfFinancialData, getBfFinancialData } from '@/api/bf/financial/bfFinancialData'
    export default {
        data() {
            return {
                otherBtnHide: false,
                // 季度字典
                quarterOptions: [],
                // 表单参数
                form: {
                  fileList: []
                },
                // 项目id
                getDealId: this.$route.query.id,
                // 遮罩层
                loading: false,
                // 表单校验
                rules: {
                  year: [{ required: true, message: this.$t('必填信息'),	trigger: 'blur' }],
                  quarter: [{ required: true, message: this.$t('必填信息'), trigger: 'blur' }]
                }
            }
        },
        mounted() {
          if (this.getDealId === undefined || this.getDealId === '' || this.getDealId === null) {
            this.getDealId = this.$route.query.lpId
          }
        },
        created() {
          this.getDicts('sys_quarter').then(response => {
            this.quarterOptions = response.data
          })
        },
        methods: {
            // 初始化数据
            init(data) {
                if (data != null && data.id !== undefined) {
                    getBfFinancialData(data.id).then(response => {
                        this.form = response.data
                    })
                } else {
                    this.reset()
                }
            },
            // 表单重置
            reset() {
                this.form = {
                    id: undefined,
                    dealId: this.$route.query.id,
                    year: undefined,
                    quarter: undefined,
                    fundTotalAssets: undefined,
                    fundNetAssets: undefined,
                    accountNetProfit: undefined,
                    administrationCost: undefined,
                    auditCost: undefined,
                    custodyFee: undefined,
                    managementFee: undefined,
                    manageTotalAmount: undefined,
                    remark: undefined,
                    fileList: [],
                    createBy: undefined,
                    createTime: undefined,
                    updateBy: undefined,
                    updateTime: undefined,
                    delFlag: undefined
                }
                this.resetForm('form')
            },
            // 取消按钮
            cancel() {
                this.$parent.$parent.formOpen = false
                this.$parent.$parent.reset()
            },
            // 关闭form页面
            closeForm() {
                // 关闭form页面遮罩层
                this.loading = false
                // 关闭form页面
                this.$parent.$parent.formOpen = false
                // 刷新list页面
                this.$parent.$parent.getList()
            },
            /** 提交按钮 */
            submitForm: function() {
                this.$refs['form'].validate(valid => {
                    if (valid) {
                        this.loading = true
                        saveBfFinancialData(this.form).then(response => {
                            if (response.code === 200) {
                                this.msgSuccess(this.$t('保存成功'))
                                this.closeForm()
                            } else {
                                this.msgError(response.msg)
                            }
                            this.loading = false
                        })
                    } else {
                      this.locationError(document)
                    }
                })
           }

        }

    }
</script>
